package day9;

import java.sql.*;
import java.util.Scanner;

public class SelectUserTest {
    //根据编号查找总共有多少个项目信息
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return;
        }
        String url = "jdbc:mysql://localhost:3306/bid?autoReconnect=true&useUnicode=true" +
                "&characterEncoding=utf8" +
                "&serverTimezone=GMT%2B8";
        String user = "root";
        String pass = "";
        Connection con = null;
        PreparedStatement st = null;
        ResultSet resultSet = null;
        //Scanner in = new Scanner(System.in);
        try {
            con = DriverManager.getConnection(url, user, pass);
            String sql = "select count(*) as t from project";
            st=con.prepareStatement(sql);//sql参数
            resultSet =st.executeQuery();
            if(resultSet.next()){
                //resultSet.getLong(1)
                long total=resultSet.getLong(1);
                System.out.println(total);
                //System.out.println(resultSet.getLong("t"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                st.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                con.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
